impl Shell {
pub fn create(out: Box<Write + Send>, config: ShellConfig) -> Shell {
+ // Match from_env() to determine if creation of a TerminfoTerminal is possible regardless
+ // of the tty status. --color options are parsed after Shell creation so always try to
+ // create a terminal that supports color output. Fall back to a no-color terminal or write
+ // output to stderr if a tty is present and color output is not possible.
match ::term::terminfo::TermInfo::from_env() {
Ok(ti) => {
// Color output is possible.
use cargo::core::shell::{Shell, ShellConfig};
use cargo::core::shell::ColorConfig::{Auto,Always, Never};
+use cargo::util::process;
-use support::{Tap, shell_writes};
+use support::{Tap, cargo_dir, execs, shell_writes};
fn setup() {
}
assert_that(&buf[..], shell_writes("Hey Alex\n"));
});
-test!(no_term {
- let config = ShellConfig { color_config: Always, tty: false };
- let a = Arc::new(Mutex::new(Vec::new()));
-
- ::std::env::remove_var("TERM");
- Shell::create(Box::new(Sink(a.clone())), config).tap(|shell| {
- shell.say("Hey Alex", color::RED).unwrap();
- });
- let buf = a.lock().unwrap().clone();
- assert_that(&buf[..], shell_writes("Hey Alex\n"));
-});
-
test!(color_explicitly_disabled {
let term = TerminfoTerminal::new(Vec::new());
if term.is_none() { return }
color::RED).unwrap()));
});
+test!(no_term {
+ // Verify that shell creation is successful when $TERM does not exist.
+ assert_that(process(&cargo_dir().join("cargo")).unwrap()
+ .env_remove("TERM"),
+ execs().with_stderr(""));
+});
+
fn colored_output(string: &str, color: color::Color) -> io::Result<String> {
let mut term = TerminfoTerminal::new(Vec::new()).unwrap();
try!(term.reset());